package com.caipiao.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
 * Created by Administrator on 2018/10/30.
 */
public class StringUtil {
    /**
     * 是否为空
     * @param str
     * @return
     */
    public static Boolean isEmpty(String str){
        if(str == null || "".equals(str)){
            return true;
        }
        return false;
    }


    /**
     * 读取txt文件的内容
     * @param path 想要读取的文件clesses下的路径
     * @return  返回文件内容
     */
    public static String txt2String(String path){
        StringBuilder result = new StringBuilder();
        try{
            path = Thread.currentThread().getContextClassLoader().getResource(path).getPath();
            File file = new File(path);
            BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
            String s = null;
            while((s = br.readLine())!=null){//使用readLine方法，一次读一行
                result.append(System.lineSeparator()+s);
            }
            br.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return result.toString();
    }

    public static void main(String[] args){
        System.out.println(txt2String("key/prKey.txt"));
        Thread.currentThread().getContextClassLoader().getResource("").getPath();
    }
}
